/**
 * 跟进值获取节点
*/
export function getNodeByValue(value, data, valueField, childrenField) {
  let result
  if (!value || !data) {
    return result
  }
  const loop = (data) => {
    if (!data || !data.length) {
      return
    }
    return data.some(v => {
      if (v[valueField] === value) {
        result = v
        return true
      }
      return loop(v[childrenField])
    })
  }
  loop(data)
  return result
}

/**
 * 跟进值获取节点
*/
export function getClosestNodes(value, data, valueField, childrenField) {
  let result = []
  if (!value || !data) {
    return result
  }
  const loop = (data) => {
    if (!data || !data.length) {
      return
    }
    return data.some(v => {
      if (v[valueField] === value) {
        result.push(v)
        return true
      }
      if (loop(v[childrenField])) {
        result.push(v)
        return true
      }
    })
  }
  loop(data)
  return result
}
